package elvis.qq.client.view;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *@category LoginView
 * @author Elvis
 *
 */
public class QQClientLogin extends JFrame{

	private int width = 450;
	private int height = 325;
	private int Swidth = Toolkit.getDefaultToolkit().getScreenSize().width;
	private int Sheight = Toolkit.getDefaultToolkit().getScreenSize().height;
	
	private JTextField account;
	private JTextField password;
	private JLabel picture;
	private JButton login,register,findPass;
	private BufferedImage bgImage = null;
	private JCheckBox rememberPass, loginAuto;
	private Container c;
	
	MyPaint mp = new MyPaint();
	
	public QQClientLogin(){
		this.setLocation((Swidth-height)/2, (Sheight-width)/2);
		this.setTitle("Java QQ");
		this.setSize(width, height);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setContentPane(mp);
		this.setLayout(null);
		
		c = this.getContentPane();
		
		picture = new JLabel(new ImageIcon("Image/QQ.png"));
		picture.setBounds(30, 120, 100, 100);
		c.add(picture);
		
		account = new JTextField("Account");
		password = new JTextField("Password");
		account.setBounds(150, 130, 190, 30);
		password.setBounds(150, 170, 190, 30);
		c.add(account);
		c.add(password);
		
		rememberPass = new JCheckBox("remember Pass",false);
		loginAuto = new JCheckBox("Auto Login",false);
		rememberPass.setBounds(150, 210, 120, 20);
		loginAuto.setBounds(270,210,90,20);
		c.add(rememberPass);
		c.add(loginAuto);
		
		login = new JButton(new ImageIcon("Image/LoginB.png"));
		login.setBounds(145, 245, 170, 40);
		c.add(login);
		
		register = new JButton(new ImageIcon("Image/register.png"));
		findPass = new JButton(new ImageIcon("Image/findPass.png"));
		register.setBounds(355, 135, 60, 20);
		findPass.setBounds(355, 175, 80, 20);
		c.add(register);
		c.add(findPass);
	    //JLabel imageLabel = new JLabel(new ImageIcon("Image/LoginBackground.png")); 
		//mainBG = new JPanel();
		//mainBG.add(imageLabel, BorderLayout.CENTER);
		
		//c.add(mainBG);
		
		try {
			bgImage =ImageIO.read(this.getClass().getResource("LoginBackground.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		this.setVisible(true);
	}
	
	public static void main(String [] args){
		new QQClientLogin();
	}
	
	class MyPaint extends JPanel{
		public void paintComponent(Graphics g){
			super.paintComponent(g);
			BufferedImage bi = new BufferedImage(700,710,BufferedImage.TYPE_INT_ARGB);
			Graphics g2 = bi.createGraphics();
			g2.drawImage(bgImage, 0, 0, this);
			g.drawImage(bi, 0, 0, this);
			
		}
	}
}
